//
//  AppDelegate.m
//  DSYDouban
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "AppDelegate.h"
#import "RootViewController.h"
#import "MovieViewController.h"
#import "CinemaViewController.h"
#import "MyViewController.h"
#import "DBManager.h"

@interface AppDelegate ()

@property (nonatomic, retain) NSMutableArray *userArr;

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [_userArr release];
    
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [_window release];
    
    RootViewController *rooVC = [[RootViewController alloc] init];
    UINavigationController *rootNAV = [[UINavigationController alloc] initWithRootViewController:rooVC];
    rootNAV.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"活动" image:[UIImage imageNamed:@"activity.png"] tag:1000] autorelease];
    
    
    MovieViewController *movieVC = [[MovieViewController alloc] init];
    UINavigationController *movieNAV = [[UINavigationController alloc] initWithRootViewController:movieVC];
    movieNAV.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"电影" image:[UIImage imageNamed:@"movie.png"] tag:1001] autorelease];
    
    
    CinemaViewController *cinemaVC = [[CinemaViewController alloc] init];
    UINavigationController *cinemaNAV = [[UINavigationController alloc] initWithRootViewController:cinemaVC];
    cinemaNAV.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"影院" image:[UIImage imageNamed:@"cinema.png"] tag:1002] autorelease];
    
    MyViewController *myVC = [[MyViewController alloc] init];
    UINavigationController *myNAV = [[UINavigationController alloc] initWithRootViewController:myVC];
    myNAV.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"user.png"] tag:1003] autorelease];
    
    UITabBarController *tab = [[UITabBarController alloc] init];
    tab.viewControllers = @[rootNAV, movieNAV, cinemaNAV, myNAV];
    _window.rootViewController = tab;
    
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bg_nav.png"] forBarMetrics:UIBarMetricsDefault];
    
    [rooVC release];
    [movieVC release];
    [cinemaVC release];
    [myVC release];
    
    
    [rootNAV release];
    [movieNAV release];
    [cinemaNAV release];
    [myNAV release];
    
    [tab release];
    
    
    // 数据库的检测
    [self  testDB];
    
    return YES;
}


// 数据库测试
- (void)testDB {
    // 数据库的加载
    [[DBManager createDB] open];
    
    // 创建表
    [[DBManager createDB] create];
    
//    [[DBManager createDB] insert:nil];
    
//    NSMutableArray *array = [[DBManager createDB] select:nil];
//    
//    for (NSMutableDictionary *dic in array) {
//        NSLog(@"%@    %@", [dic objectForKey:@"username"], [dic objectForKey:@"password"]);
//    }
    
}



- (void)userHandle {
    
    self.userArr = [NSMutableArray array];
    
    // 创建两个个数组
    NSMutableArray *myMovieArr = [NSMutableArray arrayWithObjects:@"仙逆", @"完美世界", nil];
    NSMutableArray *myActivityArr = [NSMutableArray arrayWithObjects:@"ios开发者大会", @"BBS开发会谈", nil];
    
    // 创建一个字典
    NSMutableDictionary *myDic = [NSMutableDictionary dictionary];
    [myDic setObject:@"dsy" forKey:@"username"];
    [myDic setObject:@"dsy1672" forKey:@"password"];
    [myDic setObject:@"870929851@qq.com" forKey:@"email"];
    [myDic setObject:@"15382022130" forKey:@"phone"];
    // 是否处于登陆状态
    [myDic setObject:@"on" forKey:@"status"];
    // 将两个数组添加寄来
    [myDic setObject:myActivityArr forKey:@"activity"];
    [myDic setObject:myMovieArr forKey:@"movie"];
    // 将整个字典添加到数组中
    [_userArr addObject:myDic];
    
    
    
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
